import request from "@/utils/request";

//1.获取spu所有销售属性列表
//销售属性每一项
export interface reqSpuBaseSaleItemType {
  id?: number;
  name: string;
}
//销售属性列表类型
export type reqSpuBaseSaleType = reqSpuBaseSaleItemType[];
//获取spu所有销售属性列表
export const requestAllBaseSaleAttrList = () => {
  return request.get<any, reqSpuBaseSaleType>(
    "/admin/product/baseSaleAttrList"
  );
};

//spu图片列表每一项类型
export interface reqSpuImageListItemType {
  id?: number;
  imgName: string;
  imgUrl: string;
  spuId?: number;
  name?: string,
  url?: string,
  response?: any
}
//spu图片列表类型
export type reqSpuImageListType = reqSpuImageListItemType[];
//spu销售属性值每一项类型
export interface reqSpuSaleAttrValueListItemType {
  baseSaleAttrId?: number;
  id?: number;
  isChecked?: string;
  saleAttrName?: string;
  saleAttrValueName: string;
  spuId?: number;
}
//spu销售属性值列表类型
export type reqSpuSaleAttrValueListType = reqSpuSaleAttrValueListItemType[];
//spu销售属性每一项类型
export interface reqSpuSaleAttrListItemType {
  baseSaleAttrId?: number;
  id?: number;
  saleAttrName: string;
  spuId?: number;
  spuSaleAttrValueList: reqSpuSaleAttrValueListType;
  isEdit?: boolean,
  inputValue?: string
}
//spu销售属性列表类型
export type reqSpuSaleAttrListType = reqSpuSaleAttrListItemType[];
//spu完整的信息类型
export interface reqSpuInfoType {
  category3Id: number | null;
  description: string;
  id?: number;
  spuImageList: reqSpuImageListType | null;
  spuName: string;
  spuSaleAttrList: reqSpuSaleAttrListType | null;
  tmId?: number | null;
}
//spu列表类型
export type reqSpuListType = reqSpuInfoType[];
//spu分页类型
export interface reqSpuPageType {
  records: reqSpuListType;
  total: number;
  size: number;
  current: number;
  searchCount: boolean;
  pages: number;
}
//2.添加spu
export const requestAddSpu = (spuInfo: reqSpuInfoType) => {
  return request.post<any, null>("/admin/product/saveSpuInfo", spuInfo);
};
//3.修改spu
export const requestUpdateSpu = (spuInfo: reqSpuInfoType) => {
  return request.post<any, null>("/admin/product/updateSpuInfo", spuInfo);
};
//4.删除spu
export const requestDeleteSpu = (spuId: number) => {
  return request.delete<any, null>(`/admin/product/deleteSpu/${spuId}`);
};
//5.获取spu分页列表
export const requestSpuPage = (page:number,limit:number,category3Id:number) => {
    return request.get<any,reqSpuPageType>(`/admin/product/${page}/${limit}?category3Id=${category3Id}`)
}
//6.根据spuId获取当前spu图片列表
export const requestNowSpuImageList = (spuId:number) => {
    return request.get<any,reqSpuImageListType>(`/admin/product/spuImageList/${spuId}`)
}
//7.根据spuId获取当前spu销售属性列表
export const requestNowSpuSaleAttrList = (spuId:number) => {
    return request.get<any,reqSpuSaleAttrListType>(`/admin/product/spuSaleAttrList/${spuId}`)
}